package com.ckcool.blog.controller;

import com.ckcool.blog.dao.mapper.SysUserMapper;
import com.ckcool.blog.dao.pojo.SysUser;
import com.ckcool.blog.service.LoginService;
import com.ckcool.blog.vo.Result;
import com.ckcool.blog.vo.params.LoginParam;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author ckcool
 */

@RestController
@RequestMapping("login")
public class LoginController {

    @Resource
    private LoginService loginService;

    @Resource
    private SysUserMapper sysUserMapper;

    @PostMapping
    public Result login(@RequestBody LoginParam loginParam) {
        //验证 用户
        return loginService.login(loginParam);
    }
    private static final String slat = "ckcool!@#";

    @GetMapping("/update/{id}")
    public Result updateById(@PathVariable("id") Long id) {
        String password = "admin";
        password = DigestUtils.md5Hex(password + slat);
        SysUser sysUser = sysUserMapper.selectById(id);
        sysUser.setPassword(password);
        return Result.success(sysUser);
    }
}
